import 'dart:developer';

import 'package:english_words/english_words.dart';
import "package:flutter/material.dart";
import 'package:flutter_app0311/mine/RandomWords.dart';
import 'package:flutter_app0311/mine/ScaffoldRoute.dart';
import 'package:flutter_app0311/mine/SingleChildScrollViewTestRoute.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.topCenter,
      child: Wrap(
        spacing: 8.0, // 主轴(水平)方向间距
        runSpacing: 4.0, // 纵轴（垂直）方向间距
        children: <Widget>[
          Text(
            "我是首页",
            style: TextStyle(
                color: Colors.blue,
                fontSize: 18.0,
                height: 1.2,
                fontFamily: "Courier",
                background: new Paint()..color = Colors.yellow,
                decoration: TextDecoration.underline,
                decorationStyle: TextDecorationStyle.dashed),
          ),
          RaisedButton.icon(
            icon: Icon(Icons.send),
            label: Text("发送"),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                final wordPair = new WordPair.random();
                debugPrint("xlbflutter" + wordPair.asPascalCase);

                return ScaffoldRoute();
              }));
            },
          ),
          OutlineButton.icon(
            icon: Icon(Icons.add),
            label: Text("添加"),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                return SingleChildScrollViewTestRoute();
              }));
            },
          ),
          FlatButton.icon(
            icon: Icon(Icons.info),
            label: Text("详情"),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                return RandomWords();
              }));
            },
          ),
          FlatButton(
            color: Colors.blue,
            highlightColor: Colors.blue[700],
            colorBrightness: Brightness.dark,
            splashColor: Colors.grey,
            child: Text("Submit"),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(20.0)),
            onPressed: () {},
          ),
          Image(image: AssetImage("images/avatar.png"), width: 16.0),
          Image.network(
            "https://avatars2.githubusercontent.com/u/20411648?s=460&v=4",
            width: 100.0,
          ),
          Image(
            image: AssetImage("images/avatar.png"),
            width: 100.0,
            color: Colors.blue,
            colorBlendMode: BlendMode.difference,
          ),
          // 模糊进度条(会执行一个动画)
          LinearProgressIndicator(
            backgroundColor: Colors.grey[200],
            valueColor: AlwaysStoppedAnimation(Colors.blue),
          ),
//进度条显示50%
          LinearProgressIndicator(
            backgroundColor: Colors.grey[200],
            valueColor: AlwaysStoppedAnimation(Colors.blue),
            value: .5,
          ),
          // 宽高不等
          SizedBox(
            height: 100,
            width: 130,
            child: CircularProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: AlwaysStoppedAnimation(Colors.teal),
              // value: .7,
            ),
          ),
        ],
      ),
    );
  }
}

class _SwitchAndCheckBoxTestRouteState extends State {
  bool _switchSelected = true; //维护单选开关状态
  bool _checkboxSelected = true; //维护复选框状态
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Switch(
          value: _switchSelected, //当前状态
          onChanged: (value) {
            //重新构建页面
            setState(() {
              _switchSelected = value;
            });
          },
        ),
        Checkbox(
          value: _checkboxSelected,
          activeColor: Colors.red, //选中时的颜色
          onChanged: (value) {
            setState(() {
              _checkboxSelected = value;
            });
          },
        )
      ],
    );
  }
}
